package com.crm.custinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.crm.custinfo.domain.BlackList;
import com.crm.custinfo.service.IBlackListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 黑名单管理Controller
 * 
 * @author ruoyi
 * @date 2024-01-13
 */
@RestController
@RequestMapping("/crmsys/blacklist")
public class BlackListController extends BaseController
{
    @Autowired
    private IBlackListService blackListService;

    /**
     * 查询黑名单管理列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlackList blackList)
    {
        startPage();
        List<BlackList> list = blackListService.selectBlackListList(blackList);
        return getDataTable(list);
    }

    /**
     * 导出黑名单管理列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:export')")
    @Log(title = "黑名单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlackList blackList)
    {
        List<BlackList> list = blackListService.selectBlackListList(blackList);
        ExcelUtil<BlackList> util = new ExcelUtil<BlackList>(BlackList.class);
        util.exportExcel(response, list, "黑名单管理数据");
    }

    /**
     * 获取黑名单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blackListService.selectBlackListById(id));
    }

    /**
     * 新增黑名单管理
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:add')")
    @Log(title = "黑名单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlackList blackList)
    {
        blackList.setCerateBy(getLoginUser().getUser().getNickName());
        return toAjax(blackListService.insertBlackList(blackList));
    }

    /**
     * 修改黑名单管理
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:edit')")
    @Log(title = "黑名单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlackList blackList)
    {
        blackList.setCerateBy(getLoginUser().getUser().getNickName());
        return toAjax(blackListService.updateBlackList(blackList));
    }

    /**
     * 删除黑名单管理
     */
    @PreAuthorize("@ss.hasPermi('crmsys:blacklist:remove')")
    @Log(title = "黑名单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blackListService.deleteBlackListByIds(ids));
    }
}
